// packageA/pages/kaihei2/kaihei2.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    name:'',
    ggid:'',
    gglist:'',
    list1:[
      '胜率高','被邀次数多','游戏等级高','被拉黑数少'
    ],
    type:-1,
    type1:-1,
    navlist1:[
      '不限','男','女'
    ],
    saixuan:false,
    navlist2: [{
      id: "1",
      title: "已收藏",
      xz_flag: false
    },
    {
      id: "2",
      title: "同城",
      xz_flag: false
    },
    {
      id: "3",
      title: "开黑过",
      xz_flag: false
    },{
      id: "4",
      title: "可开黑",
      xz_flag: false
    },
    {
      id: "5",
      title: "皇冠会员",
      xz_flag: false
    }
    ],
    shouhua:false,
    type2:-1,
    navlist3:[
      '1','2','5','10','20','50'
    ],
    idx:'',
    page_no:1
  },
  z_open(){
    this.setData({
      saixuan:true
    })
  },
  z_close(){
    let navlist2 = [{
      id: "1",
      title: "已收藏",
      xz_flag: false
    },
    {
      id: "2",
      title: "同城",
      xz_flag: false
    },
    {
      id: "3",
      title: "开黑过",
      xz_flag: false
    },{
      id: "4",
      title: "可开黑",
      xz_flag: false
    },
    {
      id: "5",
      title: "皇冠会员",
      xz_flag: false
    }
    ]
    this.setData({
      type:0,
      type1:0,
      navlist2:navlist2
    })
  },
  z_open1(){
    this.setData({
      shouhua:true
    })
  },
  z_close1(){
    this.setData({
      shouhua:false
    })
  },
  z_wancheng(){
    this.setData({
      saixuan:false
    })
    this.z_jilu()
  },
  z_sea(e){
    this.setData({
      name:e.detail.value
    })
  },
  z_jiangpin(){
    this.z_jilu()
  },
  z_shaixuan1(e){
    this.setData({
      type:e.currentTarget.dataset.index + 1
    })
    this.z_jilu()
  },
  z_shaixuan2(e){
    this.setData({
      type1:e.currentTarget.dataset.index + 1
    })
  },
  z_shaixuan3: function (e) {
    let _this = this
    let index = e.currentTarget.dataset.index
    let xz_flag = e.currentTarget.dataset.xz_flag
    let id = e.currentTarget.dataset.id
    if (xz_flag) {
      _this.setData({
        [`navlist2[${index}].xz_flag`]: false,
      })
    } else {
      _this.setData({
        [`navlist2[${index}].xz_flag`]: true
      })
    }
  },
  z_shaixuan4(e){
    let _this = this
    _this.setData({
      type2:e.currentTarget.dataset.nums,
      idx:_this.data.navlist3[e.currentTarget.dataset.index].nums
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.guanggao1()
    this.z_yonghu()
    this.z_jianzhi()
    this.z_jilu()
    this.z_xianhua()
  },
  guanggao1(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advertPage',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log(res.data.data)
         _this.guanggao2()
      }
    })
  },
  guanggao2(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/advert?page_id=11',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           gglist:res.data.data[0]
         })
      }
    })
  },
  z_kvlianjia(e){
    let _this = this
    let link_url = e.currentTarget.dataset.url
    let id = e.currentTarget.dataset.url
    if(link_url != undefined){
      wx.navigateTo({
        url: link_url,
      })
    }
  },
  z_yonghu(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
       if(res.data.code == '1001'){
         _this.setData({
           login:true,
           yonghu:res.data.data
         })
       }
      }
    })
  },
  z_jianzhi(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/memberYqInfo',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           jianzhi:res.data.data,
           type2:res.data.data.byq_min_xh
         })
      }
    })
  },
  z_jilu(){
    let _this = this
    let order_type = _this.data.type
    if(order_type > 0){
      order_type = order_type - 1
    }
    let sex = ''
    if(_this.data.type1 == 1){
      sex = '不限'
    } else if(_this.data.type1 == 2){
      sex = '男'
    } else if(_this.data.type1 == 3){
      sex = '女'
    }
    let sx_ysc = ''
    if(_this.data.navlist2[0].xz_flag == true){
      sx_ysc = '1'
    }
    let sx_tc = ''
    if(_this.data.navlist2[1].xz_flag == true){
      sx_tc = '1'
    }
    let sx_khg = ''
    if(_this.data.navlist2[2].xz_flag == true){
      sx_khg = '1'
    }
    let sx_kkh = ''
    if(_this.data.navlist2[3].xz_flag == true){
      sx_kkh = '1'
    }
    let sx_hg = ''
    if(_this.data.navlist2[4].xz_flag == true){
      sx_hg = '1'
    }
    let params = {
      "token":wx.getStorageSync("user_token"),
      "order_type": order_type,
      "sex":sex,
      "sx_ysc":sx_ysc,
      "sx_tc":sx_tc,
      "sx_khg":sx_khg,
      "sx_kkh":sx_kkh,
      "sx_hg":sx_hg
    }
    wx.request({
      url: app.apiurl + 'api/member/memberYqRecord?page_no=' + _this.data.page_no + '&page_num=10&name=' + _this.data.name,
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
           list:res.data.data.list
         })
      }
    })
  },
  z_xianhua(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/xianhuaList',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
         _this.setData({
          navlist3:res.data.data
         })
      }
    })
  },
  z_shouhua(){
    let _this = this
    let params = {
      "token":wx.getStorageSync("user_token"),
      "byq_min_xh":_this.data.idx
    }
    wx.request({
      url: app.apiurl + 'api/member/byqMinXhNum',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        wx.showToast({
          title: res.data.msg,
          icon: 'none',
          duration: 2000
        })
         _this.setData({
           shouhua:false
         })
         _this.z_jianzhi()
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
 
//  let _this = this
//  let page_no  = _this.data.page_no
//  page_no = page_no+1
//  _this.setData({
//    page_no:page_no
//  })
//  _this.z_jilu()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})